package com.xx.controller.xunyou.app;

import com.xx.controller.util.MyCachUtil;
import com.xx.springBootUtil.result.JsonResult;
import com.xx.springBootUtil.validate.ValidateType;
import com.xx.springBootUtil.validate.ValidateWriteIn;
import com.xx.xunyou.entity.item.vo.IndexVo;
import com.xx.xunyou.service.XunyouGoodService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @program: xunyou-parent
 * @author: zhl
 * @create: 2019-05-20
 **/
@Api(value = "API - XunyouGoodController", description = "点赞")
@RestController
public class XunyouGoodController {

    @Autowired
    private XunyouGoodService xunyouGoodService;

    /**
     * 点赞
     * @param token
     * @param objectId
     * @param typeId
     * @return
     */
    @ApiOperation(value = "点赞", notes = "点赞", response = JsonResult.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "用户验证TOKEN - Y", dataType = "string", required = true, paramType = "query"),
            @ApiImplicitParam(name = "objectId", value = "实体的id", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "typeId", value = "类型", dataType = "int", required = true, paramType = "query"),
    })
    @ApiResponses({@ApiResponse(code = 200, message = "")})
    @ValidateWriteIn(parameter = {"token","objectId","typeId"},type = {ValidateType.TOKEN})
    @RequestMapping(value = "app/good/insert", method = RequestMethod.POST)
    public JsonResult insert(String token, Integer objectId, Integer typeId){
        Integer userId = MyCachUtil.getUserIdByToken(token);
        xunyouGoodService.insert(userId, objectId, typeId);

        return new JsonResult();
    }

    /**
     * 删除点赞
     */
    @ApiOperation(value = "删除点赞", notes = "删除点赞", response = JsonResult.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "用户验证TOKEN - Y", dataType = "string", required = true, paramType = "query"),
            @ApiImplicitParam(name = "objectId", value = "实体的id", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "typeId", value = "类型", dataType = "int", required = true, paramType = "query"),
    })
    @ApiResponses({@ApiResponse(code = 200, message = "")})
    @ValidateWriteIn(parameter = {"token","objectId","typeId"},type = {ValidateType.TOKEN})
    @RequestMapping(value = "app/good/delete", method = RequestMethod.POST)
    public JsonResult delete(String token, Integer objectId, Integer typeId){
        Integer userId = MyCachUtil.getUserIdByToken(token);
        xunyouGoodService.delete(userId, objectId, typeId);

        return new JsonResult();
    }
}
